import createDOMElement from './createDOMElement';
import unmountNode from './unmountNode'
export default function mountNativeElement(virtualDOM, container, oldDOM) {
  // 转换DOM对象
  let newElement = createDOMElement(virtualDOM)
  
  // 将转换后的DOM对象放置在页面中
  if(oldDOM) {
    container.insertBefore(newElement, oldDOM)
  }else {
    container.appendChild(newElement)
  }

  // 判断旧的DOM对象是否存在，如果存在删除
  if(oldDOM) {
    unmountNode(oldDOM)
  }
  const component = virtualDOM.component
  if(component) {
    component.setDOM(newElement)
  }
}